import request from '@/utils/request'
// import qs from 'qs'

// 静态路由

// 获取ipv4列表
export function getIpv4Array (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/getIpv4Array',
    method: 'post',
    data
  })
}

// 添加静态路由IPv4
export function addIpv4 (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/addIpv4',
    method: 'post',
    data
  })
}

// 删除静态路由IPv4
export function delIpv4 (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/del_ipv4',
    method: 'post',
    data
  })
}

// 获取ipv6列表
export function getIpv6Array (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/getIpv6Array',
    method: 'post',
    data
  })
}

// 添加静态路由IPv6
export function addIpv6 (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/addIpv6',
    method: 'post',
    data
  })
}

// 删除静态路由IPv6
export function delIpv6 (params) {
  var data = fromData(params)
  return request({
    url: 'static_route/del_ipv6',
    method: 'post',
    data
  })
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
